package com.dhcy.mqtt.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Configuration
public class UploadFilePathConfig implements WebMvcConfigurer {

    @Value("${BASEIMGPATH}")
    private String BASEIMGPATH;

    @Value("${PROJECTNAME}")
    private String PROJECTNAME;

	@Value("${baseStaticUrl}")
	private String baseStaticUrl;

    @Resource(name="thymeleafViewResolver")
    private ThymeleafViewResolver thymeleafViewResolver;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
       // registry.addViewController("/" + PROJECTNAME + "/**").setViewName("file:" + BASEIMGPATH);
        registry.addResourceHandler("/" + PROJECTNAME + "/**").addResourceLocations("file:" + BASEIMGPATH);
        if (thymeleafViewResolver != null) {
            Map<String, Object> vars = new HashMap<>(1);
            vars.put("staticUrl", baseStaticUrl);
            thymeleafViewResolver.setStaticVariables(vars);
        }
    }

}
